package com.zr.exception;

import com.zr.enums.CoreExceptionEnum;
import lombok.Getter;

@Getter
public class ServiceException extends RuntimeException{

    /**
     * 异常状态码
     */
    private int code;

    public ServiceException(CoreExceptionEnum em) {
        super(em.getMessage());
        this.code = em.getCode();
    }

    /**
     * @param em  异常枚举对象
     * @param cause   原编译期异常，此处可将编译期异常转化为运行期异常，cause为原编译期异常内容需手动添加
     */
    public ServiceException(CoreExceptionEnum em, Throwable cause) {
        super(em.getMessage(), cause);
        this.code = em.getCode();
    }

    public ServiceException(int code, String message) {
        super(message);
        this.code = code;
    }

    public ServiceException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

}
